<?
require("../dbconnect.php");
require("../share_function.php");



if (!empty($_GET['id'])) {
    $id = $_GET['id'];
    $get_id = mysql_query("select * from os_products where id='$id'") or die(mysql_error());
}



if (mysql_num_rows($get_id) == 0) {
    header("Location:os_invalid.php?error=5");
}


$a = mysql_fetch_array($get_id, MYSQL_ASSOC);
$id = $a['id'];
$get_sub_cat = mysql_query("select * from os_sub_category where id=" . $a['sub_cat_id']);
$cat_id = $a['sub_cat_id'];
$get_cat = mysql_query("select * from os_category where id=" . $a['cat_id']);
$total_view = mysql_query("update os_products set total_view=total_view+1 where id=$id");
if (mysql_num_rows($get_sub_cat) == 0) {
    $sub_cat = "Unknown";
} else {
    $sub_cat = mysql_result($get_sub_cat, 0, "name_eng");
}

if (mysql_num_rows($get_cat) == 0) {
    $main_cat = "Unknown";
    $main_cat_id = "0";
} else {
    $main_cat = mysql_result($get_cat, 0, "name_eng");
    $main_cat_id = mysql_result($get_cat, 0, "id");
}




$title = $a['product_name_eng'];
?>



<table width="100%" cellpadding="5" cellspacing="0">
    <Tr>
        <td width="20%" valign="top">
            <table width="100%">

                <?
                $get_photo = mysql_query("select * from os_productpic where product_id='$id' order by order_id asc");

                if (mysql_num_rows($get_photo) != 0) {
                    $row = 0;
                    $secondrow1 = "";
                    $secondrow2 = "";
                    $isFirstRow = 1;
                    while ($photo = mysql_fetch_array($get_photo, MYSQL_ASSOC)) {
                        $piclink = $photo["name"];
                        if ($photo["width"] - $photo["height"] > 0) {
                            $fix = "width=80";
                        } else {
                            $fix = "height=80";
                        }


                        if ($row % 2 == 0) {
                            $secondrow1 = "<tr>";
                            $secondrow2 = "</tr>";
                            $isFirstRow++;
                        } else {
                            $secondrow1 = "";
                            $secondrow2 = "";
                        }
                        $photo_id = $photo['id'];
                        $image_link = ROOT_PATH . "productpic/thumbnails/" . $piclink;
                        ?>
                        <?= $secondrow1 ?>
                        <Td align="center" valign="top">
                            <img src='required/thumbnail_resize.php?width=120&height=120&cropratio=1:1&image=<?= $image_link ?>' class='product_thumbnail_frame' />

                        </td>

                        <?
                        $row++;
                    }
                    ?>
                    <?= $secondrow2; ?>
                    <?
                }
                ?>


            </table>
        </Td>

        <td valign="top" width="80%">

            <table width="100%">
                <Td class="product_title">                     
                    <?= $a['product_name_eng'] ?>
                </Td>


                <tr valign="top">
                    <td valign="top" ><br>

                        <?= $a['description_eng'] ?>
                        <br><br>
                        <strong>Product code</strong> : <?= $a['product_code'] ?>
                    </td>
                </tr>

                <tr>
                    <td align="center" >
                        <input type="button" value="Close" class="button" onclick="closeColorBox()">
                    </td>
                </tr>
            </table>
        </td> 
    </tr>	
</table>
